#import "UIButtonControl.h"
#import "ColorFactory.h"
#import "FontFactory.h"
@implementation CUIButtonControl

-init
{
	[super init];
	iButton=[[UIButton buttonWithType:UIButtonTypeDetailDisclosure] retain];
	//iButton=[[UIButton alloc ] initWithFrame:CGRectZero];
	[self addSubview:iButton];
	return self;
}


-(void)CustomInit
{
	UIFont *font;
	font=[CFontFactory CreateFontBySizeAndWeight:self.iFontSize weightTag:self.iFontWeight];
	iButton.titleLabel.font=font;
	[iButton setTitle:self.iText forState:UIControlStateNormal];

	//iButton.titleLabel.text=@"dd";
	iButton.backgroundColor = [UIColor clearColor];
	if(self.iBackColor)
		iButton.backgroundColor=[CColorFactory CreateRgbCorol:self.iBackColor];
	if(self.iFontColor)
	{
		iButton.titleLabel.textColor=[CColorFactory CreateRgbCorol:self.iFontColor];
	}else
	{
		//iButton.titleLabel.textColor=[UIColor blackColor];
		[iButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	}
	//	iButton.textColor=[CColorFactory CreateRgbCorol:self.iFontColor];
	
}

-(void)CaculateSize
{
	int fatherWidth;
	int width;
	CGRect rect;
	CGSize size;
	CGPoint pt;
	fatherWidth=self.iFatherWidth;
	width=fatherWidth*self.iWidthPt/100;
	rect.origin.x=0;
	rect.origin.y=0;
	rect.size.width=width;
	rect.size.height = self.iFatherHeight;
	self.bounds = rect;
	iButton.bounds = rect;
	if (rect.size.height < size.height)
		rect.size.height=size.height;
	if(self.tag == 0)
		rect.size.width=width;
	else 
		rect.size.width=size.width;//超链接下划线用
	pt.x = rect.size.width / 2;
	pt.y = rect.size.height / 2;
	self.bounds = rect;
	self.center = pt;
	iButton.bounds = rect;
	iButton.center = pt;
	
}

- (void)AddTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
{
	[iButton addTarget:target action:action forControlEvents:controlEvents];
}
-(void)dealloc
{
	if(iButton)
		[iButton release];
	[super dealloc];
}

@end